<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>综合服务系统--试卷库新增</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/supplier/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <link rel="stylesheet" href="/plugin/it/common/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/zTree/js/jquery.ztree.all.js" charset="utf-8"></script>
</head>
<style>
    .Right {
        width: 100%;
        overflow-y: auto;
    }

    .screening ul li:nth-child(1) select, .screening ul li:nth-child(3) select, .screening ul li:nth-child(6) select {
        width: 30%;
    }

    .layui-btns {
        display: inline-block;
        height: 38px;
        line-height: 38px;
        padding: 0 18px;
        background-color: #fff;
        color: #00a0e9;
        border-color: #00a0e9;
        border-width: 2px;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border-radius: 5px;
        cursor: pointer;
        float: right;
        margin-right: 14%;
    }

    .layui-laypage .layui-laypage-curr .layui-laypage-em {
        background: #5775EF;
    }

    .layui-btn-primary:hover {
        border-color: #5775EF;
        color: #5775EF;
    }

    .layui-breadcrumb a:hover {
        color: #5775EF !important;
    }

    .layui-btn-normal {
        background: #5775EF;
    }
</style>

<body>
<!--头部-->
<div style="background-color: #F1F4FB;padding-left: 20px;">
    <span class="layui-breadcrumb" lay-separator=">">
        <a><cite>考试管理</cite></a>
        <a href="/ex/exPaper/sjkIndex"><cite>试卷库</cite></a>
        <a href="#"><cite>试卷详情</cite></a>
    </span>
</div>
<!--容器-->
<div class="container clearfix">
    <div class="Right fr">
        <form class="layui-form" enctype="multipart/form-data">
            <div class="screening screeningOne whitebg clearfix" style="margin-top: 0;">
                <input hidden="hidden" id="hiddId" value="${eq.paperId}">
                <div class="bold">试卷设置</div>
                <label class="fl"><span class="red">*</span>试卷名称：</label>
                <input disabled="true" value="${eq.paperName}" id="paperName" name="paperName" class="fl"
                       lay-maxlength="3" type="text"
                       style="border: 1px solid #eee;"/>
                <ul class="clearfix fl" style="width: 100%;margin-top: 10px">
                    <li style="width: 25%;">
                        <label class="fl"><span class="red">*</span>试卷分类：</label>
                        <select disabled="true" value="${eq.paperSort}" name="paperSort" class="ml8 " id="paperSort"
                                lay-verify="required"
                                lay-ignore style="width: 120px;">
                            <option value="">请选择</option>
                            <#list stfl as vo>
                                <option value="${vo.badtCode}"
                                        <#if (eq.paperSort)??>
                                            <#if (eq.paperSort) ==(vo.badtCode)>
                                                selected=selected
                                            </#if>
                                        </#if>
                                >${vo.badtName}</option>
                            </#list>
                        </select>
                    </li>
                    <li style="width: 25%">
                        <label class="fl"><span class="red">*</span> 试卷类型：</label>
                        <select disabled="true" value="${eq.paperType}" name="paperType" class="ml8 " id="paperType"
                                onchange="queryNone(this)"
                                lay-verify="required"
                                lay-ignore style="width: 120px;">
                            <option value="">请选择</option>
                            <option value="001"
                                    <#if (eq.paperType)??><#if (eq.paperType) == '001'>selected="selected"</#if></#if>>
                                固定试卷
                            </option>
                            <option value="002"
                                    <#if (eq.paperType)??><#if (eq.paperType) == '002'>selected="selected"</#if></#if>>
                                随机试卷
                            </option>
                        </select>
                    </li>
                    <li style="width: 25%;">
                        <label class="fl"><span class="red">*</span> 总分数：</label>
                        <input value="${eq.totalScore}" id="totalScore" name="totalScore" class="fl" lay-maxlength="3"
                               type="text"
                               style="border: 1px solid #eee;width: 100px" disabled="true" value="0"
                               lay-verify="maxlength"/>
                    </li>
                    <li style="width: 25%;float: right">
                        <a href="javascript:void(0)" onclick="gdst()" id="gdst" style="display:none"
                           class="layui-btn layui-btn-primary layui-border-blue">添加固定试题</a>
                        <a href="javascript:void(0)" onclick="sjst()" id="sjst" style="display:none"
                           class="layui-btn layui-btn-primary layui-border-blue">添加随机试题</a>
                    </li>
                </ul>
            </div>
        </form>
        <div class="project whitebg" style="margin-top: 20px">
            <table id="tableList" class="layui-hide" lay-filter="tableList"></table>
        </div>
        <div class="releaseBtn center">
            <button type="button" class="layui-btn layui-btn-normal white ft18 close">返回</button>
        </div>
    </div>
    <form class="layui-form" id="tests" style="display:none; margin-top: 22px;padding-top: 20px">
        <ul class="clearfix" style="width: 100%;margin-top: 10px">
            <li style="width: 90%;margin-top: 20px;margin-left: 10%">
                <label style="width: 20%"><span class="red">*</span>试题题型：</label>
                <select name="sttx" class="ml8 " id="sttx" lay-verify="required" style="width: 70%" lay-ignore>
                    <option value="001">请选择</option>
                    <#list sttx as vo>
                        <option value="${vo.badtCode}"
                        >${vo.badtName}</option>
                    </#list>
                </select>
            </li>
            <li style="width: 90%;margin-top: 20px;margin-left: 10%">
                <label style="width: 20%"><span class="red">*</span>试题分类：</label>
                <select name="stfl" class="ml8 " id="stfl" lay-verify="required" style="width: 70%" lay-ignore>
                    <option value="001">请选择</option>
                    <#list stfl as vo>
                        <option value="${vo.badtCode}"
                        >${vo.badtName}</option>
                    </#list>
                </select>
            </li>
            <li style="width: 90%;margin-top: 20px;margin-left: 10%">
                <label style="width: 20%"><span class="red">*</span>试题难度：</label>
                <select name="stnd" class="ml8 " id="stnd" lay-verify="required" style="width: 70%" lay-ignore>
                    <option value="001">请选择</option>
                    <#list stnd as vo>
                        <option value="${vo.badtCode}"
                        >${vo.badtName}</option>
                    </#list>
                </select>
            </li>
            <li style="width: 90%;margin-top: 20px;margin-left: 10%">
                <label style="width: 20%"><span class="red">*</span>试题数量：</label>
                <input id="stsl" name="stsl" type="text" style="border: 2px solid #eee;width: 55%"/>
                <span style="width: 15%">/${count}</span>
            </li>
            <li style="width: 90%;margin-top: 20px;margin-left: 10%">
                <label style="width: 20%"><span class="red">*</span>每题分数：</label>
                <input id="mtfs" name="mtfs" type="text" style="border: 2px solid #eee;width: 70%"/>
            </li>
        </ul>
    </form>
    <div id="test" style="display:none; margin-top: 22px;">
        <form class="layui-form">
            <ul class="clearfix" style="width: 100%;margin-top: 10px">
                <li style="width: 20%;float: left">
                    <label class="fl"><span class="red">*</span>试题名称：</label>
                    <input id="content" name="content" class="fl" type="text"
                           style="border: 1px solid #eee;width: 63%"/>
                </li>
                <li style="width: 20%;float: left">
                    <label class="fl"><span class="red">*</span> 试题题型：</label>
                    <select name="quType" class="ml8 " id="quType" lay-verify="required"
                            lay-ignore>
                        <option value="">请选择</option>
                        <#list sttx as vo>
                            <option value="${vo.badtCode}"
                            >${vo.badtName}</option>
                        </#list>
                    </select>
                </li>
                <li style="width: 20%;float: left">
                    <label class="fl"><span class="red">*</span>试题分类：</label>
                    <select name="quCategory" class="ml8 " id="quCategory" lay-verify="required"
                            lay-ignore>
                        <option value="">请选择</option>
                        <#list stfl as vo>
                            <option value="${vo.badtCode}"
                            >${vo.badtName}</option>
                        </#list>
                    </select>
                </li>
                <li style="width: 20%;float: left">
                    <label class="fl"><span class="red">*</span> 试题难度：</label>
                    <select name="level" class="ml8 " id="level" lay-verify="required"
                            lay-ignore>
                        <option value="">请选择</option>
                        <#list stnd as vo>
                            <option value="${vo.badtCode}"
                            >${vo.badtName}</option>
                        </#list>
                    </select>
                </li>
                <li style="width: 20%;float: left">
                    <input class="layui-btns fr" type="button" value="搜索" onclick="query()">
                </li>
            </ul>
            <div class="project whitebg" style="margin-top: 20px">
                <table id="stList" lay-data="{id:'stList'}" class="layui-hide" lay-filter="stList"></table>
            </div>
            <ul class="clearfix" style="width: 100%;margin-top: 10px">
                <li style="width: 20%;float: right">
                    <label class="fl"><span class="red">*</span>已选择试题数：</label>
                    <input id="num" name="num" class="fl" type="text" style="border: 1px solid #eee;width: 45%"
                           disabled="true" value="0"/>
                </li>
                <li style="width: 20%;float: right">
                    <label class="fl"><span class="red">*</span>设置每道题分数：</label>
                    <input id="score" name="score" class="fl" lay-maxlength="3" type="text"
                           style="border: 1px solid #eee;width: 45%"/>
                </li>
            </ul>
        </form>
    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/tabs.js"></script>
<script type="text/javascript">
    $(function () {

    })
    var list = [];
    var layer;
    var form;
    var table = null;
    var table2 = null;
    var tableIns = null;
    var tableInsTwo = null;
    var layedit;
    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element = "";
    layui.use(['jquery', 'layer', 'table', 'form', 'laytpl', 'laydate', 'element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var upload = layui.upload;
        window.check = function (bjq) {
            layedit.build(bjq);
        };

        //监听选择框  同步已选择题数
        table.on('checkbox(stList)', function (obj) {
            var items = table.checkStatus('stList')
            $('#num').val(items.data.length);
        });
        tablelist();
    });
    //取消按钮
    $('.close').click(function () {
        window.parent._showtab('5253b2f369364ceca7dbca94a85b68ca', '试卷库', '/ex/exPaper/sjkIndex');
    });
    $(function () {
        $("#wd").hide();
        $("#pd").hide();
        $("#tk").hide();
        $("#duox").hide();
    })

    //选择试卷类型进行切换数据
    function queryNone(obj) {
        var code = $(obj).find('option:selected').val();
        var tabledata = layui.table.cache.tableList;
        var _aln = tabledata.length;
        if (code == "001") {
            $("#sjst").css("display", "none");
            $("#gdst").css("display", "block");
        }
        if (code == "002") {
            $("#gdst").css("display", "none");
            $("#sjst").css("display", "block");
        }
        if (_aln > 0) {
            var id = $("#hiddId").val()
            deleteList(id, "1");
        }
    }

    function tablelist() {
        layui.use('table', function () {
            table = layui.table;
            var id = $("#hiddId").val();
            //方法级渲染
            tableIns = table.render({
                id: 'tableList',
                elem: '#tableList',
                url: '/ex/exPaper/stkList?id=' + id,
                height: "full-230",
                page: true,
                cols: [[
                    {
                        title: '序号', width: '10%', templet: function (res) {
                            return res.LAY_INDEX;
                        }
                    },
                    {field: 'quId', title: 'ID', hide: true, sort: false},
                    {field: 'content', title: '试题名称', width: '20%', sort: false},
                    {field: 'quCategory', title: '试题分类', width: '25%', sort: false},
                    {field: 'quType', title: '试题类型', width: '15%',},
                    {field: 'level', title: '试题难度', width: '15%'},
                    {field: 'score', title: '分数', width: '14%'}

                ]]
            });
        });
    }

    function deleteList(id, type) {
        var str = "";
        if (type == 1) {
            str = "类型变更会导致数据丢失,是否继续";
        } else {
            str = "确认删除";
        }
        layer.confirm(str, {
            btn: ['确定', '取消'] //按钮
        }, function () {
            layerAjaxGet('/ex/exPaper/deleteList', {id: id, type: type}, '', function (d) {
                if (d.code == 1) {
                    refreshTotalScore();
                    table.reload('tableList');
                    layer.closeAll();
                } else {
                    layer.msg(d.msg, {icon: 2});
                    layer.closeAll();
                }
            });
        })
        return false;
    }

    function gdst() {
        $("#num").val(0);
        $("#score").val("");
        layer.open({
            type: 1,
            area: ['80%', '90%'],
            title: '添加固定试题',
            content: $("#test"),
            shade: 0,
            btn: ['返回', '提交']
            , btn1: function (index, layero) {
                layer.closeAll();
            },
            btn2: function (index, layero) {
                var items = table.checkStatus('stList')
                var strs = [];
                for (let i = 0; i < items.data.length; i++) {
                    strs.push(items.data[i].quId);
                }
                strs.join(',');
                var id = $("#hiddId").val();
                var score = $("#score").val();
                if (score == "") {
                    layer.msg("请填写每题分数", {icon: 2});
                    return false;
                }
                layerAjaxGet('/ex/exPaper/insertPaperRelGd', {
                    id: id,
                    strs: strs,
                    score: score,
                    paperSort: paperSort,
                    paperType: paperType,
                    paperName: paperName
                }, '', function (d) {
                    if (d.code == 1) {
                        var num = $("#num").val();
                        var x = parseInt(score) * parseInt(num);
                        var s = $("#totalScore").val();
                        if (s == 0) {
                            $("#totalScore").val(x);
                        } else {
                            $("#totalScore").val(x + parseInt(s));
                        }
                        table.reload('tableList');
                        layer.closeAll();
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            },
            cancel: function (layero, index) {
                layer.closeAll();
            }
        });
        tablest();
    }

    function sjst() {
        layer.open({
            type: 1,
            area: ['100%', '100%'],
            title: '添加随机试题',
            content: $("#tests"),
            shade: 0,
            btn: ['提交']
            , btn1: function (index, layero) {
                var id = $("#hiddId").val();
                var sttx = $("#sttx").val();
                var stfl = $("#stfl").val();
                var stnd = $("#stnd").val();
                var stsl = $("#stsl").val();
                var mtfs = $("#mtfs").val();
                if (sttx == "") {
                    layer.msg("请填写试题题型", {icon: 2});
                    return false;
                }
                if (stfl == "") {
                    layer.msg("请填写试题分类", {icon: 2});
                    return false;
                }
                if (stnd == "") {
                    layer.msg("请填写试题难度", {icon: 2});
                    return false;
                }
                if (stsl == "") {
                    layer.msg("请填写试题数量", {icon: 2});
                    return false;
                }
                if (mtfs == "") {
                    layer.msg("请填写每题分数", {icon: 2});
                    return false;
                }
                var param = {
                    paperName: $('#paperName').val(),
                    paperType: $('#paperType').val(),
                    paperSort: $('#paperSort').val(),
                    id: id,
                    quType: sttx,
                    num: stsl,
                    level: stnd,
                    quCategory: stfl,
                    score: mtfs
                };
                layerAjaxGet('/ex/exPaper/insertPaperRelSj', param, '', function (d) {
                    if (d.flag) {
                        let oldTotalScore = $('#totalScore').val();
                        $('#totalScore').val(parseInt(oldTotalScore) + stsl * mtfs);
                        layer.msg(d.msg, {icon: 1});
                        table.reload('tableList');
                        layer.closeAll();
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            },
            end: function () {
                var id = $("#hiddId").val();
                //刷新页面,
                var jsondata = {
                    id: id
                };
                table2.reload('tableList', {where: jsondata});
            },
            cancel: function (layero, index) {
                layer.closeAll();
            }
        });
    }

    function tablest() {
        table2 = layui.table;
        var id = $("#hiddId").val();
        //方法级渲染
        tableInsTwo = table2.render({
                id: 'stList',
                elem: '#stList',
                url: '/ex/exPaper/stkListByType?quId=' + id,
                height: 400,
                page: false,
                cols: [[
                    {checkbox: true},
                    {
                        title: '序号', width: '4%', templet: function (res) {
                            return res.LAY_INDEX;
                        }
                    },
                    {field: 'quId', title: 'ID', hide: true, sort: false},
                    {field: 'content', title: '试题名称', width: '20%', sort: false},
                    {field: 'quCategory', title: '试题分类', width: '15%', sort: false},
                    {field: 'quType', title: '试题题型', width: '15%',},
                    {field: 'level', title: '试题难度', width: '10%'},
                    {field: 'remark', title: '操作', width: '20%', toolbar: "#toolBarRow"}

                ]]
            }
        );
    }

    function query() {
        var id = $("#hiddId").val();
        var level = $("#level").val();
        var quCategory = $("#quCategory").val();
        var quType = $("#quType").val();
        var content = $("#content").val();
        var jsondata = {
            id: id,
            level: level,
            quCategory: quCategory,
            quType: quType,
            content: content
        };
        table2.reload('stList', {where: jsondata});
    }

    function createSt(status) {
        var id = $("#hiddId").val();
        var paperName = $("#paperName").val();
        var paperSort = $("#paperSort").val();
        var paperType = $("#paperType").val();
        var totalScore = $("#totalScore").val();
        var datajson = {
            paperId: id,
            paperName: paperName,
            paperType: paperType,
            totalScore: totalScore,
            paperSort: paperSort,
            totalTime: '30',
            zjType: paperSort,
            status: status
        }
        layerAjaxGet('/ex/exPaper/insertPaper', datajson, '', function (res) {
            if (res.code === 1) {
                layer.msg(res.msg, {icon: 1});
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        });
    }

    function submitSt() {
        var tabledata = layui.table.cache.tableList;
        var _aln = tabledata.length;
        var id = $("#hiddId").val();
        var paperName = $("#paperName").val();
        var paperSort = $("#paperSort").val();
        var paperType = $("#paperType").val();
        var totalScore = $("#totalScore").val();
        var datajson = {
            id: id,
            paperName: paperName,
            paperType: paperType,
            totalScore: totalScore,
            paperSort: paperSort,
            status: "002"
        }
        layerAjaxGet('/ex/exPaper/insertPaperSj', datajson, '', function (d) {
            if (d.flag == true) {
                layer.closeAll();
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });
    }

    function refreshTotalScore() {
        layerAjaxGet('/ex/exPaper/refreshTotalScore', {paperId: $('#hiddId').val()}, '', function (res) {
            $('#totalScore').val(res);
        });
    }
</script>
</body>

</html>